Skip to content

Conversation

@ihower
Copy link
Contributor

@ihower ihower commented Nov 27, 2025

Resolved: 2130

This PR fixes a bug where Runner.run_streamed() could hang forever if session.add_items() raises an exception during streaming.

Root cause

When an exception happens in the outer error handling of _start_streaming, the completion sentinel is not sent. Because of that, the event queue never receives QueueCompleteSentinel, and stream_events() waits forever.

Solution

This PR marks the stream as complete in the outer error handling when is_complete is still False, so the stream will not hang and the exception can be raised to the caller.

A regression test is added to make sure exceptions are properly raised instead of causing the stream to hang.

@seratch seratch added bug Something isn't working feature:core feature:sessions labels Dec 2, 2025
@seratch seratch added this to the 0.6.x milestone Dec 2, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@seratch seratch merged commit 7a14b4b into openai:main Dec 2, 2025
9 checks passed
@seratch seratch changed the title Fix streaming hang when session.add_items raises an exception Fix #2130 streaming hang when session.add_items raises an exception Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming hangs indefinitely when session.add_items() raises an exception

2 participants